<?php

use Illuminate\Database\Seeder;

class CommentTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //

        $faker = Faker\Factory::create('zh-CN');
        $post_ids = \App\Models\Post::all()->pluck('id')->toArray();
        $datas = [];
        foreach (range(1, 10) as $key => $value) {
            $datas[] = [
                'post_id' => $faker->randomElement($post_ids),
                'parent_id' =>  null ,
                'username' =>  $faker->userName ,
                'email' =>  $faker->safeEmail ,
                'content' =>  $faker->text ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('comments')->insert($datas);


        $comment_ids=\App\Models\Comment::pluck("id")->toArray();
        $comments = [];
        foreach (range(1, 20) as $key => $value) {
            $comments[] = [
                'post_id' => $faker->randomElement($post_ids),
                'parent_id' =>  $faker->randomElement($comment_ids) ,
                'username' =>  $faker->userName ,
                'email' =>  $faker->safeEmail ,
                'content' =>  $faker->text ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('comments')->insert($comments);

    }
}
